package com.moli.iov.admin.web.controller;

import com.moli.iov.admin.model.vo.req.BaseVo;
import com.moli.iov.alarm.model.dto.req.StatAlarmParamDto;
import com.moli.iov.alarm.remote.IAlarmStatRemoteService;
import com.moli.iov.handle.alarm.enums.AlarmCategoryEnum;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.sys.enums.UserTypeEnum;
import com.moli.iov.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@RestController
public class StatAlarmController extends BaseController{

    @Reference(group = "${service.group}", check = false)
    private IAlarmStatRemoteService alarmStatRemoteService;

    @RequestMapping("/alarm/offline/stat")
    public RestResponse getStatAlarmRisk(@RequestBody StatAlarmParamDto dto){

        if(dto!=null){
            dto.setAlarmCategory(AlarmCategoryEnum.RISK_OFFLINE_ALARM.getFlag());

            BaseVo baseVo = getBaseVo();
            if(UserTypeEnum.COMPANY.getFlag() == baseVo.getSysUserType()){
                dto.setCompanyId(baseVo.getSysCompanyId());
            }
        }
        return alarmStatRemoteService.getStatAlarmDetail(dto);
    }

    public static void main(String[] args) {
        StatAlarmParamDto dto = new StatAlarmParamDto();
        dto.setCompanyId(1L);
        List<Integer> list = new ArrayList<>();
        list.add(1);
        dto.setReportTypeList(list);
        dto.setReportCategory(1);
        dto.setEndTime(new Date());
        dto.setBeginTime(new Date());
        System.out.println(JsonUtils.toJson(dto));
    }

    @RequestMapping("/alarm/terminal/stat")
    public RestResponse getStatAlarmDevice(@RequestBody StatAlarmParamDto dto){
        if(dto!=null){
            dto.setAlarmCategory(AlarmCategoryEnum.DEVICE_ALARM.getFlag());

            BaseVo baseVo = getBaseVo();
            if(UserTypeEnum.COMPANY.getFlag() == baseVo.getSysUserType()){
                dto.setCompanyId(baseVo.getSysCompanyId());
            }
        }
        return alarmStatRemoteService.getStatAlarmDetail(dto);
    }

    @RequestMapping("/alarm/fence/stat")
    public RestResponse getStatAlarmFence(@RequestBody StatAlarmParamDto dto){
        if(dto!=null){
            dto.setAlarmCategory(AlarmCategoryEnum.FENCE_ALARM.getFlag());

            BaseVo baseVo = getBaseVo();
            if(UserTypeEnum.COMPANY.getFlag() == baseVo.getSysUserType()){
                dto.setCompanyId(baseVo.getSysCompanyId());
            }

        }
        return alarmStatRemoteService.getStatAlarmDetail(dto);
    }

}
